var swiperbox;

function initBox() {
  w_width = jQuery(window).width();
  w_height = jQuery(window).height();
  $(".industry-slide,.industry-slide figure").css("height", w_height);
  setImgMax($(".industry-slide figure img"), 1920, 1080, w_width, w_height);
}
initBox();
jQuery(window).resize(function () {
  initBox();
});

var indexFn = {
  //数字滚动判断
  NumberIf: true,
  Number: [],
  AboutNumberIf: true,
  AboutNumberTime: null,
  init: function () {
    this.getBanner();
    this.getIndex();
    this.getProduct();
    this.getPerform();
   
  },

  getBanner: function () {
    // 节流
    var canScroll = true;
    // 状态
    var type = 0;
    //第二屏的1秒缓冲时间
    var cTime = true;
    if (!isMobile) {
      var activeMaxPage = 4;
      var that = this;

      swiperbox = new Swiper(".home-swiper", {
        speed: 1000,
        slidesPerView: "auto",
        direction: "vertical",
        loop: false,
        touchRatio: "0",
        noSwiping: true,
        nested: true,
        //禁止滑动时swiper移动
        followFinger: false,
        mousewheel: true,
        parallax: true,
        paginationClickable: true,
        breakpoints: {
          //当宽度小于等于320
          1024: {
            mousewheelControl: false,
          },
        },
        on: {
          init: function () {
            console.log("动画开始");
            $(".index_page_content")
              .eq(this.realIndex)
              .addClass("index_page_current");
            // 初始化时添加事件监听
            addNextSlideButtonListener();
            addTopButtonListener();
            setTimeout(function () {
              $(".have_no_method").hide();
            }, 1000);
          },
          slideChangeTransitionStart: function () {
            let e = {};
            e.activeIndex = this.activeIndex;
            //页面滑动时触发事件

            if (swiperbox) {
              swiperbox.mousewheel.enable();
            }
            cTime = true;

            // 修改右侧按钮
	        if (e.activeIndex == 0) {
	          	// console.log('右侧按钮第一屏隐藏')
	          	$(".right-navigate").hide();
	          	$('.top-button').hide();
	        } else {
	          	$(".right-navigate").show();
	          	$('.top-button').show();
	          }
            if (e.activeIndex == 2 || e.activeIndex == 0) {
              $(".right-navigate").addClass("Colors");
            } else {
              $(".right-navigate").removeClass("Colors");
            }

            if (e.activeIndex >= 0) {
              $(".right-navigate").addClass("show");
            }
            if (e.activeIndex == 4) {
              $(".right-navigate").removeClass("show");
            }

            // 判断第二屏显隐
            if (e.activeIndex == 1) {
            	// console.log('第二屏')
            	that.IndexAboutNumber();//about number
              	setTimeout(() => {
              		// console.log('公司新增类名生效')
	                $(".concerning-zindex").addClass("swiper-slide-prev");
	                $(".five_left_1").addClass("five_active");
              	}, 500);
            } else {
            	that.AboutNumberIf = true;
                clearTimeout(that.AboutNumberTime);
	              $(".concerning-zindex").removeClass("swiper-slide-prev");
	              $(".five_left_1").removeClass("five_active");
	              // console.log("从第二屏走了");
            }

            if (e.activeIndex == 2) {
              $(".fade_test").addClass("fade_1");
      				setTimeout(() => {
      					$('.pro_title .newsplus_title').addClass('articleShow')
      					$('.pro_title .newsplus_titles').addClass('articleShow')
      				}, 500)
				
            } else {
              $(".fade_test").removeClass("fade_1");
              $("#main .my-container").css({ opacity: "0", transition: "0" });
      			  $('.pro_title .newsplus_title').removeClass('articleShow')
      			  $('.pro_title .newsplus_titles').removeClass('articleShow')
            }
            if (e.activeIndex == 3) {
              setTimeout(() => {
                $('.perform .newsplus_title').addClass('articleShow')
                $('.perform .newsplus_titles').addClass('articleShow')
              }, 500)
            } else {
               $('.perform .newsplus_title').removeClass('articleShow')
               $('.perform .newsplus_titles').removeClass('articleShow')
            }
            if (e.activeIndex == 4) {
            	// console.log('最后一屏')
              $(".ljx").css({
                transform: `translate3d(0px, ${swiperbox.height - $(".footer")["0"].clientHeight}px, 0px)`,
              });
            } else {
              $(".ljx").css({ transform: `translate3d(0px, 0px, 0px)` });
              
            }
           
            $(".navigate-li li")
              .eq(e.activeIndex)
              .addClass("active")
              .siblings()
              .removeClass("active");

            // 切换屏幕时重新添加事件监听
            addNextSlideButtonListener();
            addTopButtonListener();
          },
        },


      });
      // 添加下一屏按钮点击事件监听器
      function addNextSlideButtonListener() {
        $(".down_click").off("click"); // 移除之前的点击事件监听
        $(".down_click").on("click", function () {
          swiperbox.slideNext(); // 跳转到下一屏
        });
      }
      // 添加返回顶部按钮点击事件监听器
      function addTopButtonListener() {
        $(".top-button").off("click"); // 移除之前的点击事件监听
        $(".top-button").on("click", function () {
          swiperbox.slideTo(0); // 返回到第一屏
        });
      }
    //点击右侧按钮时候的方法
      $(".navigate-li li").click(function () {
          let e = {
              activeIndex: null
          }
          if (swiperbox) {
              swiperbox.mousewheel.enable();
          }
          e.activeIndex = $(this).index()
          $(this).addClass("active").siblings().removeClass("active");
          swiperbox.slideTo($(this).index(), 800, true);
          if ($(this).index() == 1) {
              $(".right-navigate").removeClass("Colors");
              $(".top-button").show();
              $(".about_k").show();
          } else if ($(this).index() == 0) {
              $(".right-navigate").hide();

          } else if ($(this).index() == 2) {
              $(".right-navigate").addClass("Colors");

           } else {
              $(".right-navigate").removeClass("Colors");
              $(".top-button").show();
              // console.log('第几屏', e.activeIndex)
          }

      });

      //第二屏 公司
      var conSwiper = new Swiper(".concerning-swiper", {
        speed: 1000,
        loop: false,
        mousewheelControl: true,
        autoplay: 0,
        effect: "fade",
        direction: "vertical",
        mousewheelReleaseOnEdges: true,
        mousewheel: true,
        autoHeight: true,
        releaseOnEdges: true,
        onTransitionStart: function (e) {
          swiperbox.disableMousewheelControl();
          if (this.activeIndex == 1) {
            setTimeout(() => {
              swiperbox.disableMousewheelControl();
            }, 300);
          } else {
            setTimeout(() => {
              swiperbox.enableMousewheelControl();
            }, 1000);
          }
        },
        onTransitionEnd: function (e) {
          if (e.activeIndex == 1) {
            $(".right-navigate").addClass("Colors");
            $(".concerning .scroll-more").removeClass("scroll-more1");
          } else {
            $(".right-navigate").removeClass("Colors");
            $(".concerning .scroll-more").addClass("scroll-more1");
          }
        },
      });
    }
  },
  getIndex: function () {
     function banSiper() {
         // 首页banner
          var banFlag = 0;
          const index_banner_swp = new Swiper('.index_banner', {
              loop: true,
              effect: 'fade',
              simulateTouch: false, //禁止鼠标模拟
              observer: true,
              observeParents: true,
              autoplay: {
                  delay: 4000,
                  stopOnLastSlide: false,
                  disableOnInteraction: false,
              },
              navigation: {
                  nextEl: '.ban_next',
                  prevEl: '.ban_prev',
              },
              // 如果需要分页器
              pagination: {
                  el: '.index_banner .swiper-pagination',
                  clickable: true,
              },
              on: {
                  slideChangeTransitionEnd: function () {
                      banFlag = this.activeIndex;
                  },
                  slideChange: function () {
                      banFlag = this.activeIndex;
                      if ($('.index_banner .swiper-slide').eq(banFlag).find('video').length == 1) {
                          $("video").get(0).currentTime = 0;
                          $("video").eq(0).trigger("play");
                          $("video").eq(0).attr("muted", "muted")
                      } else {
                          $('.index_banner .swiper-slide').find('video').trigger("pause");
                      }
                  }
              },

          });

          // 开始
          $('.start').on('click', function () {
              $(this).hide();
              $(".suspend").show();
              index_banner_swp.autoplay.stop();

          });
          // 暂停
          $('.suspend').on('click', function () {
              $(this).hide();
              $(".start").show();
              index_banner_swp.autoplay.start();
          });

     }
    banSiper();
  },
  //产品切换
  getProduct: function () {
    function proSiper() {
      var swiperPro = new Swiper(".product-swiper", {
        speed: 1000,
        slidesPerView: 3,
        parallax: true,
        centeredSlides: true,
        loop: true,
        touchRatio: "0.5",
        autoHeight: true,
        loopedSlides: 5,
        navigation: {
            nextEl: '.product-prev.next',
            prevEl: '.product-prev.prev',
        },
        pagination :{
    			el: '.swiper-pagination',
    			clickable :true,
    		},
        breakpoints: {
          1024: {
            slidesPerView:3,
            spaceBetween: 0,
          },
          991: {
            slidesPerView:1,
            speed: 800,
            autoHeight: false,
            spaceBetween: 15,
            loopedSlides: 0,
            parallax: false,
          },
          767: {
            slidesPerView:1,
            speed: 800,
            autoHeight: false,
            spaceBetween: 15,
            parallax: false,
            noSwiping: true,
            noSwipingClass: 'pro-slide',
          },
        },
        on: {
        	slideChangeTransitionStart: function(){
   				$(".pro-slide.swiper-slide-prev").siblings().removeClass("abcdef");
            		$(".pro-slide.swiper-slide-prev").eq(0).prev().addClass("abcdef");
          	},
  		},

        // onSlideChangeStart: function (swiper) {
        //   $(".pro-slide.swiper-slide-prev").siblings().removeClass("abcdef");
        //   $(".pro-slide.swiper-slide-prev").eq(0).prev().addClass("abcdef");
        // },
      });
    }
    proSiper();

    $(".product-btn a").click(function () {
      $(this).addClass("active").siblings().removeClass("active");
      $(".product-item").eq($(this).index()).stop().fadeIn().siblings().hide();
      proSiper();
    });
  },
  //典型业绩
  getPerform: function () {
    function performSiper() {
      var swiperPorm = new Swiper(".perform_swiper", {
        speed: 800,
        slidesPerView: 5,
        noSwiping: true,
        nested: true,
        followFinger: false,
        navigation: {
            nextEl: '.perform-next',
            prevEl: '.perform-prev',
        },
        breakpoints: {
          1024: {
            slidesPerView:4,
          },
          991: {
            slidesPerView:3,
          },
          767: {
            slidesPerView:1,
            noSwiping: true,
            noSwipingClass: 'perform-slide',
          },
        },

       
      });
    }
    performSiper();
  },
  //about number
  IndexAboutNumber: function () {
      var that = this;
      if (that.AboutNumberIf) {
          that.AboutNumberTime = setTimeout(function () {
              var numberL = $('.index_about_item_number');// 获取所有包含数字的元素
              for (var i = 0; i < numberL.length; i++) {
                  numberL.eq(i).html(that.Number[i]);
              }
              $('.index_about_item_number').each(function () {
                  $(this).prop('counter', 0).animate({
                      counter: $(this).text()
                  }, {
                      duration: 1500,// 动画持续时间
                      easing: 'swing',
                      step: function (now) {
                          now = Math.ceil(now);
                          now = now.toString();
                          now = now.replace(/\B(?=(\d{3})+(?!\d))/g, '');
                          $(this).text(now);
                      }
                  });
              });
          }, 1000)//在延迟秒后执行动画
          that.AboutNumberIf = false;
      }
  },

};

// 获取当前浏览器窗口的宽度
function getWindowWidth() {
  var windowWidth =
    window.innerWidth ||
    document.documentElement.clientWidth ||
    document.body.clientWidth;
  // console.log("当前浏览器窗口宽度：" + windowWidth + " 像素");
  // 判断窗口宽度并添加/移除类名
  if (windowWidth < 1025) {
    var wh = $(window).height();
    var ww = $(window).width();
    $(".top-button").click(function () {
      $("html,body").stop().animate({ scrollTop: 0 }, 800);
    });

    $(window).scroll(function () {
      if ($(window).scrollTop() < wh) {
        $(".top-button").hide();
      } else {
        $(".top-button").show();
      }
    });
  } else {
  }
}
// 初始化时获取一次宽度
getWindowWidth();
// 窗口大小变化时重新获取宽度
window.addEventListener("resize", getWindowWidth);

indexFn.init();